286A - Lucky Permutation - CodeForces Solution


constructive algorithms math *1400

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
using namespace std;
int n,a[1000005];
int main()
{
    cin>>n;
    if(n%4!=0&&n%4!=1)
	{
        cout<<-1<<endl;
        return 0;
    }
    for(int i=1;i<n/2;i+=2)
	{
        a[i]=i+1;
        a[i+1]=n-i+1;
        a[n-i+1]=n-i;
        a[n-i]=i;
    }
    if(n%2==1) 
    {
    	a[(n/2)+1]=(n/2)+1;
	}
    for(int i=1;i<=n;i++)
	{
        cout<<a[i]<<' ';
    }
    return 0;
} 


Comments

Submit
0 Comments
More Questions

1719B - Mathematical Circus
1719C - Fighting Tournament
1642A - Hard Way
285C - Building Permutation
1719E - Fibonacci Strings
1696C - Fishingprince Plays With Array
1085A - Right-Left Cipher
1508B - Almost Sorted
1690C - Restoring the Duration of Tasks
1055A - Metro
1036D - Vasya and Arrays
1139C - Edgy Trees
37A - Towers
353A - Domino
409H - A + B Strikes Back
1262A - Math Problem
158C - Cd and pwd commands
194A - Exams
1673B - A Perfectly Balanced String
1104B - Game with string
1169B - Pairs
1567D - Expression Evaluation Error
78A - Haiku
1287A - Angry Students
1428A - Box is Pull
234B - Reading
581B - Luxurious Houses
1481C - Fence Painting
935A - Fafa and his Company
22A - Second Order Statistics